package com.example.demo2.controller;

import com.example.demo2.generator.entity.CarInsurance;
import com.example.demo2.generator.entity.R;
import com.example.demo2.generator.entity.WlManager;
import com.example.demo2.generator.service.CarInsuranceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 车辆保险(CarInsurance)表控制层
 *
 * @author makejava
 * @since 2024-09-20 09:41:17
 */
@RestController
@Api(value = "保险单Controller",tags = "保险单测试接口")
@RequestMapping("/carInsurance")
public class CarInsuranceController {
    /**
     * 服务对象
     */
    @Resource
    private CarInsuranceService carInsuranceService;

//    /**
//     * 分页查询
//     *
//     * @param carInsurance 筛选条件
//     * @param pageRequest      分页对象
//     * @return 查询结果
//     */
//    @GetMapping
//    public ResponseEntity<Page<CarInsurance>> queryByPage(CarInsurance carInsurance, PageRequest pageRequest) {
//        return ResponseEntity.ok(this.carInsuranceService.queryByPage(carInsurance, pageRequest));
//    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/byID/{id}")
    public ResponseEntity<CarInsurance> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.carInsuranceService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param carInsurance 实体
     * @return 新增结果
     */
    @PostMapping
    public R add(@RequestBody CarInsurance carInsurance) {
        return R.ok("添加成功",this.carInsuranceService.insert(carInsurance));
    }

    /**
     * 编辑数据
     *
     * @param carInsurance 实体
     * @return 编辑结果
     *
     */
    @ApiOperation("更新数据")
    @PostMapping("/updateIns")
    public ResponseEntity<CarInsurance> edit(CarInsurance carInsurance) {
        return ResponseEntity.ok(this.carInsuranceService.update(carInsurance));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @ApiOperation("删除一条数据")
    @PostMapping("/delIns")
    public ResponseEntity<Boolean> deleteById(@RequestParam("carInsId") Integer id) {
        return ResponseEntity.ok(this.carInsuranceService.deleteById(id));
    }
    @ApiOperation("批量删除保险单")
    @PostMapping("/deletes")
    public R deletesById(@RequestBody List<CarInsurance>carInsurances) {
        int deletes = carInsuranceService.deleteBatch(carInsurances);
        return R.ok( deletes,"批量删除成功删除",null);
    }

    /**
     * 查询所有保险单号
     * @return 保险单列表
     */
    @ApiOperation("查询所有保险单")
    @RequestMapping(value = "/queryAllIns",method = RequestMethod.GET)
    public R queryAllIns(){
        List<CarInsurance> carInsurances = carInsuranceService.queryAllIns();
        return R.ok("查询所有保险单成功",carInsurances);
    }
    @ApiOperation("模糊条件查询")
    @GetMapping("/queryInsByLike")
    public R queryInsByLike(CarInsurance carInsurance){
        List<CarInsurance> carInsurances = carInsuranceService.queryAllByLike(carInsurance);
        return R.ok("查询成功",carInsurances);
    }
}

